package com.example.venue_reservation_service.controller;

import com.example.venue_reservation_service.domain.Comment;
import com.example.venue_reservation_service.dto.DelDTO;
import com.example.venue_reservation_service.dto.PageDTO;
import com.example.venue_reservation_service.dto.SearchDTO;
import com.example.venue_reservation_service.service.CommentService;
import com.example.venue_reservation_service.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/comment")
@CrossOrigin
@Api("用户评论管理")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @ApiOperation("发布评论")
    @PostMapping("/create")
    public Result create(@RequestBody Comment comment){
        return commentService.createComment(comment);
    }

    @ApiOperation("超级管理员查看评论信息")
    @PostMapping("/admin")
    public Result admin(@RequestBody PageDTO dto){
        return commentService.queryComment(dto);
    }

    @ApiOperation("超级管理员撤回评论")
    @GetMapping("/withdraw/{id}")
    public Result withdraw(@PathVariable("id") Integer id){
        return commentService.withdrawComment(id);
    }

    @ApiOperation("用户查看评论信息")
    @PostMapping("/user")
    public Result user(@RequestBody SearchDTO dto){
        return commentService.queryByUser(dto);
    }

    @ApiOperation("点赞/取消点赞")
    @GetMapping("like")
    public Result like(@RequestParam("userId") Integer userId,
                       @RequestParam("commentId") Integer commentId){
        return commentService.like(userId, commentId);
    }

    @ApiOperation("移除某条评论信息")
    @PostMapping("/remove/single")
    public Result single(@RequestParam("commentId") Integer commentId, @RequestParam("userId") Integer userId){
        return commentService.singleRemove(userId, commentId);
    }

    @ApiOperation("批量移除评论信息")
    @PostMapping("/remove/batch")
    public Result batch(@RequestBody DelDTO dto){
        return commentService.batchRemove(dto);
    }
}
